<template>
	<view class="container" :style="'min-height:' +pageHei+';'">
		<u-sticky  >
			<uni-search-bar  :minHeight="54" clearButton="always" cancelButton="none"  @cancel="searchItem" v-model="searchText" @confirm="searchItem"  bgColor="#FFFFFF" :radius="10" placeholder="输入昵称, 企业, 行业等"></uni-search-bar>
		</u-sticky>
		<view class="box-list" style="padding: 30rpx 20rpx;">
			<my-card @clickCard="toUrl" :hasBtn="false" acWidth="345rpx" v-for="(item,index) in acList" :key="index" :acItem="item">
			</my-card>
		</view>
		<my-empty tipText="数据为空"  image="http://cdn.uviewui.com/uview/empty/data.png" v-if="isEmpty"></my-empty>
		<u-loadmore :status="status" v-else></u-loadmore>
	</view>
</template>

<script>
	import {
		getToken,
		setToken
	} from '@/utils/token.js'
	import {
		duplicateRemoval
	} from '@/utils/common.js'
	import {
		querySearchComp,
		querySearch
	} from '@/common/api/msg.js'
	export default {
		data() {
			return {
				//类型选项配置
				pageHei: '100vh',
				currPage: 1,
				acList: [],
				allpage: 1,
				isEmpty: false,
				status: 'loading',
				searchText: '',
				version:getToken('version')
			}
		},
		onReachBottom: function() {
			if (this.status == 'loadmore') {
				this.currPage++
				this.querySearch()
			}
		},
		
		onLoad: function(option) {
			this.searchText = option && option.keywords || ''
			uni.getSystemInfo({
				success: (res) => {
					this.pageHei = res.windowHeight * 2 + 'rpx'
				}
			})
			this.querySearch()
		},
		methods: {
			toUrl(data) {
				this.$store.commit('toUserIndex',data.item)
			},
			getNewList() {
				this.currPage = 1
				this.acList = []
				this.querySearch()
			},
		
			searchItem(){
				this.getNewList()
			},
			querySearch() {
				if(getToken('version') == 2){
					querySearchComp({
						companyNo: getToken('useNum'),
						state: 1,
						searchText: this.searchText,
						'page.current': this.currPage,
					}).then(res => {
						if (res.data) {
							this.acList = duplicateRemoval(this.acList, res.data && res.data && res.data.rows || [],
								'companyId')
							this.allpage = res.data && res.data.total
							this.currPage < this.allpage ? this.status = 'loadmore' : this.status = 'nomore'
							this.isEmpty = this.acList.length == 0 ? true : false
						}
					})
				}else{
					querySearch({
						craftsmanId: getToken('useNum'),
						state: 1,
						searchText: this.searchText,
						'page.current': this.currPage,
					}).then(res => {
						if (res.data) {
							this.acList = duplicateRemoval(this.acList, res.data && res.data && res.data.rows || [],
								'craftsmanId')
							this.allpage = res.data && res.data.total
							this.currPage < this.allpage ? this.status = 'loadmore' : this.status = 'nomore'
							this.isEmpty = this.acList.length == 0 ? true : false
						}
					})
				}
				
			},

		}
	}
</script>

<style lang="scss">
	.container {
		background-color: #F7F8FC;
	}

	.box-list {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: space-between;
	}

	.down {
		height: 100%;
		position: relative;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		flex-wrap: nowrap;

		.menu_type {
			height: 80rpx;

			.title {
				height: 100%;
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>
